package org.enwey.icarenew.APPUtils;

import java.util.regex.Pattern;

/**
 * User: Peng
 * Date: 2013-11-09
 * Time: 10:46
 */
public final class Validator {

	private static final String EMAIL_PATTERN =
            "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
                    + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    
    private static final String TRUE_PHONE = "^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$";
    
    private static final Pattern pattern = Pattern.compile(EMAIL_PATTERN);;
    private static final Pattern phonePattern = Pattern.compile(TRUE_PHONE);

    public static boolean isEmail(String input){
        return pattern.matcher(input).matches();
    }
    
    public static boolean isPhone(String input) {
    	if (input == null) {
    		return false;
    	}
    	return phonePattern.matcher(input).matches();
    }
}
